package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;
import Models.POSBeerView;

public class POSBeerViewPresenter extends AbstractPresenter<POSBeerView> {
	final String SINGLEITEM = "posBeerView";
	final String MULTIITEM = "pOSBeerViews";
	
	public ArrayList<POSBeerView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public POSBeerView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public POSBeerView createItemFromJSONObject(JSONObject jsonBeer){
		POSBeerView beer = new POSBeerView();
		try{
			beer.setID(jsonBeer.getInt("bId"));
			beer.setName(jsonBeer.getString("bName"));
			beer.setInProduction(jsonBeer.getBoolean("inProduction"));
			return beer;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(POSBeerView item){
		try{
			JSONObject json = new JSONObject();
			json.put("bId", item.getID());
			json.put("bName", item.getName());
			json.put("inProduction", item.isInProduction());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public POSBeerView getEmptyEntity(){
		POSBeerView entity = new POSBeerView();
		return entity;
	}
}
